@extends('layout.layer')

@section('layout.content')
  <div class="row">
    <div class="col-xs-12">
      <form class="form-horizontal" id="category-create" autocomplete="off">
        <div class="form-group">
          <label class="col-xs-4 control-label align-right no-padding-right b" for="type"> <span class="red">*</span> 培训类型：
          </label>
          <div class="col-xs-8">
            <p class="">{{$category->term->type->name}}</p>
          </div>
        </div>

        <div class="form-group">
          <label class="col-xs-4 control-label align-right no-padding-right b" for="branch"> <span class="red">*</span> 所属分支：
          </label>
          <div class="col-xs-8">
            <p class="">{{$category->term->branch->name}}</p>
          </div>
        </div>

        <div class="form-group">
          <label class="col-xs-4 control-label align-right no-padding-right b" for="name"> <span class="red">*</span> 计划名称：
          </label>
          <div class="col-xs-8">
            <p class="">{{$category->term->name}}</p>
          </div>
        </div>

        <div class="form-group">
          <label class="col-xs-4 control-label form-control-static align-right no-padding-right b" for="category"> <span class="red">*</span> 课程名称：
          </label>
          <div class="col-xs-6 align-middle">
            <input type="text" class="form-control" name="category" placeholder="新课程名称" value="{{$category->name}}"/>
          </div>
        </div>

        <div class="space-32"></div>
        <div class="form-group">
          <div class="col-xs-12 center">
            <button type="submit" class="btn btn-primary" style="margin-right:15px;">
              <i class="ace-icon fa fa-check"></i>
              确定
            </button>

            <button type="button" class="btn btn-light">
              <i class="ace-icon fa fa-times"></i>
              取消
            </button>
          </div>
        </div>

      </form>
    </div>
  </div>
@stop

@section('javascript')

  <script src="//cdn.bootcss.com/jquery-validate/1.19.1/jquery.validate.min.js"></script>
  <script src="{{URL::asset('assets/js/jquery-validate-methods.js')}}"></script>
  <script src="//cdn.bootcss.com/jqueryui/1.12.1/jquery-ui.min.js"></script>


  <script type="text/javascript">
      $(function () {

          $('.btn-light').on('click', function(e) {
            //parent.location.reload();
            //var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(parent.layer.index);
          });
          /**
           表单前端验证
           */
          $("#category-create").validate({
              rules: {
                  category: {required: true},
              },
              messages: {
                  category: {required: "请填写课程科目名称"},
              },


              /* 失去焦点时不验证 */
              onfocusout: false,
              onkeyup: false,
              errorElement: 'div',
              errorClass: 'help-block',

              success: function (e) {
                  $(e).closest('.form-group').removeClass('has-error');//.addClass('has-info');
                  $(e).remove();
              },

              showErrors: function (errorMap, errorList) {
                  $.each(errorList, function (i, v) {
                      layer.tips(v.message, v.element, {tips: [3,'#dd0000'], time: 2000});
                      return false;
                  });

              },

              submitHandler: function (form) {
                  $.post('{{route('train.category.update',$category->id )}}', {
                      '_token': $("input[name='_token']").attr('value'),
                      '_method': 'put',
                      'category': $("input[name='category']").val(),
                      'is_submit': true
                  }, function (data) {
                      console.log(data);
                      layer.msg(data.message, {time: 2000,shift: -1}, function () {
                          if (data.status === true) {
                              parent.location.reload();
                              parent.layer.close(parent.layer.index);
                          }
                      });

                  }, 'json').error(function (data) {
                      layer.msg(data.responseJSON.message);
                  });
              }


          });

      });
  </script>
@stop